package com.weishe.weichar;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class WeatherComparator extends WritableComparator {
	public WeatherComparator() {
		super(Weather.class, true);
	}

	@Override
	public int compare(WritableComparable a, WritableComparable b) {
		Weather w1 = (Weather) a;
		Weather w2 = (Weather) b;

		int result = Integer.compare(w1.getYear(), w2.getYear());

		if (result == 0) {
			result = Integer.compare(w1.getMonth(), w2.getMonth());
			if (result == 0) {
				result = -Double.compare(w1.getTemperature(), w2.getTemperature());
			}
		}
		return result;
	}

}
